
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>JavaRDD操作示例 · 基于spark的快速离线分析框架使用文档</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="shengshi_feiyang@yeah.net">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-cuav-chapters/cuav-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-multipart/multipart.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-fexa/fexa.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="dataset.html" />
    
    
    <link rel="prev" href="./" />
    

    </head>
    <body>
        
<div class="book">
	<div class="header-inner">
		<!-- LOGO -->
		<div class="logo"></div>
		<span class="title"></span>

		<!-- Search -->
		
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>


		<!-- Nav -->
		<ul class="header-nav">
			<li>
				<a href="https://gitee.com/shengshifeiyang/easy-spark" target="_blank">代码仓库</a>
			</li>
		</ul>
	</div>

	<div class="book-summary">
		<div class="book-summary-title">文档目录</div>
		
		
		<nav role="navigation">
			


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../develop-guide/">
            
                <a href="../develop-guide/">
            
                    
                    开发指导
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../develop-guide/geo-json-app.html">
            
                <a href="../develop-guide/geo-json-app.html">
            
                    
                    文件读取示例hello-word
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="./">
            
                <a href="./">
            
                    
                    spark基础示例
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.3.1" data-path="java-rdd.html">
            
                <a href="java-rdd.html">
            
                    
                    JavaRDD操作示例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="dataset.html">
            
                <a href="dataset.html">
            
                    
                    Dataset操作示例
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../spark-code/">
            
                <a href="../spark-code/">
            
                    
                    spark常用代码片段
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../spark-code/map.html">
            
                <a href="../spark-code/map.html">
            
                    
                    map片段
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../spark-code/flatMap.html">
            
                <a href="../spark-code/flatMap.html">
            
                    
                    flatMap片段
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../spark-code/wrapped-array.html">
            
                <a href="../spark-code/wrapped-array.html">
            
                    
                    WrappedArray解析片段
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


		</nav>
		
		
	</div>

	<!-- Content nav -->
	<div class="book-anchor">
		<div class="book-anchor-title">在这篇文章中:</div>
		<div class="book-anchor-body">

		</div>
	</div>

	<div class="book-body">
		
		<div class="body-inner">
			
			

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >JavaRDD操作示例</a>
    </h1>
</div>




			<div class="page-wrapper" tabindex="-1" role="main">
				<div class="page-inner">
					
<div id="book-search-results">
    <div class="search-noresults">
    
					<section class="normal markdown-section">
						
						<h1 id="javardd&#x64CD;&#x4F5C;&#x793A;&#x4F8B;">JavaRDD&#x64CD;&#x4F5C;&#x793A;&#x4F8B;</h1>
<p><a href="https://gitee.com/shengshifeiyang/easy-spark/tree/master/src/main/java/com/dukk/espark/apps/JavaRDDApp.java" target="_blank">&#x4EE3;&#x7801;&#x7C7B;: JavaRDDApp</a></p>
<h2 id="&#x793A;&#x4F8B;&#x4E00;-list&#x8F6C;javardd">&#x793A;&#x4F8B;&#x4E00; list&#x8F6C;JavaRDD</h2>
<p>&#x6B64;&#x5904;&#x793A;&#x4F8B;&#x5C06;&#x7B80;&#x5355;&#x7684;java&#x96C6;&#x5408;&#x8F6C;&#x6362;&#x4E3A;JavaRDD&#xFF0C;&#x5E76;&#x6267;&#x884C;foreachPartition&#x64CD;&#x4F5C;&#x904D;&#x5386;&#x8F93;&#x51FA;&#x6570;&#x636E;</p>
<pre><code class="lang-java"> String[] strDate ={<span class="hljs-string">&quot;spark&quot;</span>,<span class="hljs-string">&quot;java&quot;</span>,<span class="hljs-string">&quot;es&quot;</span>,<span class="hljs-string">&quot;python&quot;</span>,<span class="hljs-string">&quot;scala&quot;</span>,<span class="hljs-string">&quot;javaScripts&quot;</span>,<span class="hljs-string">&quot;spark&quot;</span>,<span class="hljs-string">&quot;java&quot;</span>,<span class="hljs-string">&quot;es&quot;</span>,<span class="hljs-string">&quot;python&quot;</span>,<span class="hljs-string">&quot;scala&quot;</span>,<span class="hljs-string">&quot;javaScripts&quot;</span>};
 JavaRDD&lt;String&gt; listJavaRDD = javaSparkContext.parallelize(Arrays.asList(strDate));
 listJavaRDD.foreachPartition((VoidFunction&lt;Iterator&lt;String&gt;&gt;)i-&gt;{<span class="hljs-comment">//foreachPartition&#x904D;&#x5386;&#x6570;&#x636E;</span>
     <span class="hljs-keyword">while</span> (i.hasNext()){
         logger.info(<span class="hljs-string">&quot;list&#x8F6C;Rdd&#x904D;&#x5386;&#x8F93;&#x51FA;:{}&quot;</span>, i.next());
     }
 });
</code></pre>
<p>&#x8F93;&#x51FA;&#x7ED3;&#x679C;</p>
<pre><code class="lang-java"><span class="hljs-number">20</span>/<span class="hljs-number">11</span>/<span class="hljs-number">06</span> <span class="hljs-number">11</span>:<span class="hljs-number">37</span>:<span class="hljs-number">30</span> INFO JavaRDDApp: list&#x8F6C;Rdd&#x904D;&#x5386;&#x8F93;&#x51FA;:spark
<span class="hljs-number">20</span>/<span class="hljs-number">11</span>/<span class="hljs-number">06</span> <span class="hljs-number">11</span>:<span class="hljs-number">37</span>:<span class="hljs-number">30</span> INFO JavaRDDApp: list&#x8F6C;Rdd&#x904D;&#x5386;&#x8F93;&#x51FA;:java
<span class="hljs-number">20</span>/<span class="hljs-number">11</span>/<span class="hljs-number">06</span> <span class="hljs-number">11</span>:<span class="hljs-number">37</span>:<span class="hljs-number">30</span> INFO JavaRDDApp: list&#x8F6C;Rdd&#x904D;&#x5386;&#x8F93;&#x51FA;:es
<span class="hljs-number">20</span>/<span class="hljs-number">11</span>/<span class="hljs-number">06</span> <span class="hljs-number">11</span>:<span class="hljs-number">37</span>:<span class="hljs-number">30</span> INFO JavaRDDApp: list&#x8F6C;Rdd&#x904D;&#x5386;&#x8F93;&#x51FA;:python
<span class="hljs-number">20</span>/<span class="hljs-number">11</span>/<span class="hljs-number">06</span> <span class="hljs-number">11</span>:<span class="hljs-number">37</span>:<span class="hljs-number">30</span> INFO JavaRDDApp: list&#x8F6C;Rdd&#x904D;&#x5386;&#x8F93;&#x51FA;:scala
<span class="hljs-number">20</span>/<span class="hljs-number">11</span>/<span class="hljs-number">06</span> <span class="hljs-number">11</span>:<span class="hljs-number">37</span>:<span class="hljs-number">30</span> INFO JavaRDDApp: list&#x8F6C;Rdd&#x904D;&#x5386;&#x8F93;&#x51FA;:javaScripts
<span class="hljs-number">20</span>/<span class="hljs-number">11</span>/<span class="hljs-number">06</span> <span class="hljs-number">11</span>:<span class="hljs-number">37</span>:<span class="hljs-number">30</span> INFO JavaRDDApp: list&#x8F6C;Rdd&#x904D;&#x5386;&#x8F93;&#x51FA;:spark
<span class="hljs-number">20</span>/<span class="hljs-number">11</span>/<span class="hljs-number">06</span> <span class="hljs-number">11</span>:<span class="hljs-number">37</span>:<span class="hljs-number">30</span> INFO JavaRDDApp: list&#x8F6C;Rdd&#x904D;&#x5386;&#x8F93;&#x51FA;:java
<span class="hljs-number">20</span>/<span class="hljs-number">11</span>/<span class="hljs-number">06</span> <span class="hljs-number">11</span>:<span class="hljs-number">37</span>:<span class="hljs-number">30</span> INFO JavaRDDApp: list&#x8F6C;Rdd&#x904D;&#x5386;&#x8F93;&#x51FA;:es
<span class="hljs-number">20</span>/<span class="hljs-number">11</span>/<span class="hljs-number">06</span> <span class="hljs-number">11</span>:<span class="hljs-number">37</span>:<span class="hljs-number">30</span> INFO JavaRDDApp: list&#x8F6C;Rdd&#x904D;&#x5386;&#x8F93;&#x51FA;:python
<span class="hljs-number">20</span>/<span class="hljs-number">11</span>/<span class="hljs-number">06</span> <span class="hljs-number">11</span>:<span class="hljs-number">37</span>:<span class="hljs-number">30</span> INFO JavaRDDApp: list&#x8F6C;Rdd&#x904D;&#x5386;&#x8F93;&#x51FA;:scala
<span class="hljs-number">20</span>/<span class="hljs-number">11</span>/<span class="hljs-number">06</span> <span class="hljs-number">11</span>:<span class="hljs-number">37</span>:<span class="hljs-number">30</span> INFO JavaRDDApp: list&#x8F6C;Rdd&#x904D;&#x5386;&#x8F93;&#x51FA;:javaScripts
</code></pre>
<h2 id="&#x793A;&#x4F8B;&#x4E8C;-javardd-map&#x64CD;&#x4F5C;">&#x793A;&#x4F8B;&#x4E8C; javaRdd map&#x64CD;&#x4F5C;</h2>
<pre><code>  //&#x793A;&#x4F8B;&#x4E8C;: map&#x64CD;&#x4F5C;, &#x8BA1;&#x7B97;&#x6BCF;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x957F;&#x5EA6;
  JavaRDD&lt;Integer&gt; mapJavaRdd = listJavaRDD.map((Function&lt;String, Integer&gt;)f-&gt;{
      return f.length();
  });
</code></pre><h2 id="&#x793A;&#x4F8B;&#x4E09;-filter&#x8FC7;&#x6EE4;&#x6570;&#x636E;">&#x793A;&#x4F8B;&#x4E09; filter&#x8FC7;&#x6EE4;&#x6570;&#x636E;</h2>
<pre><code> //&#x793A;&#x4F8B;&#x4E09;: filter&#x8FC7;&#x6EE4;&#x6570;&#x636E;
 JavaRDD&lt;String&gt; filterJavaRdd = listJavaRDD.filter((Function&lt;String, Boolean&gt;)f-&gt;{
     if(f.equals(&quot;es&quot;)){
         return false;
     }
     return true;
 });
</code></pre>
<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
						
					</section>
					
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

				</div>
			</div>
			
		</div>

		
		
		<a href="./" class="navigation navigation-prev " aria-label="Previous page: spark基础示例">
			<i class="fa fa-angle-left"></i>
		</a>
		
		
		<a href="dataset.html" class="navigation navigation-next " aria-label="Next page: Dataset操作示例">
			<i class="fa fa-angle-right"></i>
		</a>
		
		
		
	</div>
	<script>
		var gitbook = gitbook || [];
		gitbook.push(function() {
			gitbook.page.hasChanged({"page":{"title":"JavaRDD操作示例","level":"1.3.1","depth":2,"next":{"title":"Dataset操作示例","level":"1.3.2","depth":2,"path":"spark-base/dataset.md","ref":"spark-base/dataset.md","articles":[]},"previous":{"title":"spark基础示例","level":"1.3","depth":1,"path":"spark-base/README.md","ref":"spark-base/README.md","articles":[{"title":"JavaRDD操作示例","level":"1.3.1","depth":2,"path":"spark-base/java-rdd.md","ref":"spark-base/java-rdd.md","articles":[]},{"title":"Dataset操作示例","level":"1.3.2","depth":2,"path":"spark-base/dataset.md","ref":"spark-base/dataset.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["-sharing","-fontsettings","back-to-top-button","copy-code-button","cuav-chapters","heading-anchors","theme-fexa","popup","splitter","multipart@0.3.0"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"splitter":{},"search":{},"cuav-chapters":{"summaryMaxSize":20,"useLimitExpanded":false},"popup":{},"multipart":{},"theme-fexa":{"search-placeholder":"输入关键字搜索","logo":"./logo.png","favicon":"./favicon.ico"},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"heading-anchors":{},"highlight":{},"back-to-top-button":{},"copy-code-button":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"shengshi_feiyang@yeah.net","pdf":{"pageNumbers":true,"fontSize":18,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":30,"left":30,"top":30,"bottom":50}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{"themeFexa":{"nav":[{"url":"https://gitee.com/shengshifeiyang/easy-spark","target":"_blank","name":"代码仓库"}]}},"title":"基于spark的快速离线分析框架使用文档","gitbook":"*"},"file":{"path":"spark-base/java-rdd.md","mtime":"2020-11-09T05:19:58.609Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-11-11T07:40:22.004Z"},"basePath":"..","book":{"language":""}});
		});
	</script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-cuav-chapters/cuav-chapters.js"></script>
        
    
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/1.2.1/anchor.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-heading-anchors/anchor-style.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-fexa/fexa.js"></script>
        
    

    </body>
</html>

